package gui.catalogues.persons;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import model.Person;

public class PersonTableModel extends AbstractTableModel {
	private List<Person> peopleList;
	private String[] colNames = {"Id", "Name", "Surname", "e-mail", "teléfono"};

	public void setItemList(List<Person> peopleList) {
		this.peopleList = peopleList;
	}
	
	/* (non-Javadoc)
	 * @see javax.swing.table.AbstractTableModel#getColumnName(int)
	 */
	@Override
	public String getColumnName(int column) {
		//return super.getColumnName(column);
		// reloaded to:
		return colNames[column];
	}

	@Override
	public int getRowCount() {
		if(peopleList == null) return 0;
		//System.out.println("PersonTableModel.getRowCount.peopleList.size(): " + peopleList.size());
		return peopleList.size();
	}

	@Override
	public int getColumnCount() {
		return colNames.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Person pItem = peopleList.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return pItem.getId();
		case 1:
			return pItem.getName();
		case 2:
			return pItem.getSurname();
		case 3:
			return pItem.getIdCollateralClient();
		case 4:
			return pItem.getColClient();
		default:
			return null;
		}
	}
}